import requests
import json
import pymysql
x1 = []
x2 = []
x3 = []
x4 = []
url = 'https://rest.jfh.com/prt-citystation/govIntention/getGovIntentionList'
header ={
    "Content-Type": "application/json;charset=UTF-8",
}
for x in range(1,11):
    data = {
        'pageSize':10,'pageNum':x,'order':"desc",'sortBy':"publish_time",'budgeAmountMin':"1000"
    }
    res = requests.post(url,headers = header,data = json.dumps(data))

    print(res.status_code)

    html = res.json()
    for i in html['data']['govIntentionList']:
        x1.append(i['projectName'])
        x2.append(i['budgetAmount'])
        x3.append(i['purUnitName'])
        x4.append(i['biddingDateFrom'])
        # print (x1,x2,x3,x4)
        # print(i['projectName'],i['budgetAmount'],i['purUnitName'],i['biddingDateFrom'])

def printmysql():
    dbConnetion = pymysql.connect(
    host='localhost',
    user='root',
    password='123456',
    database='test',
    charset='utf8'
    );
    #新建游标
    cursor = dbConnetion.cursor()
    datalist = []
    for i,j,k,l in zip(x1,x2,x3,x4):
        # 建立一个列表，列表中的元素是元组
        datalist.append((i,j,k,l))
    cursor.executemany("INSERT INTO datalist values(%s,%s,%s,%s)", datalist)
    dbConnetion.commit()
    #关闭数据库连接和游标
    cursor.close()
    dbConnetion.close()
# printmysql()